package super1.laboratory;

/**
 * @author shkstart
 * @date 2022/5/10 - 21:34
 */
public class CheckAccount extends Account{
    private double overdraft; //可透支余额


    public CheckAccount(int id,double balance,double annualInterestRate,double overdraft) {
        super(id, balance, annualInterestRate);
        this.overdraft = overdraft;
    }

    public void withdraw(double amount) {
        if (amount <= getBalance()) { //余额足够消费
       //方式一
             setBalance(getBalance() - amount);
//            方式二
//            super.withdraw(amount);
            System.out.println("你的账户余额:" + getBalance());
            System.out.println("你的可透支余额:" + overdraft);
        }else if (amount > getBalance()) {
            double number = amount - getBalance();
            if(number < overdraft) {
                balance = 0;
                overdraft -= number;
                System.out.println("你的账户余额:" + getBalance());
                System.out.println("你的可透支余额:" + overdraft);
            }else {
                System.out.println("用户超过可透支额的限额");
                System.out.println("剩余透支额度为：" + overdraft);
            }
        }
    }
}
